
/*
 资料来源:
 git@osc使用教程
 http://www.kankanews.com/ICkengine/archives/5608.shtml
 */


请先注册http://git.oschina.net。

环境准备：

Xcode（直接AppStore下载安装）
Git（可以在http://code.google.com/p/git-osx-installer/下载git安装程序，或者在https://www.kernel.org/pub/software/scm/git/下载源码安装。）


//============================================================================================
步骤：
配置Git并连接到git@git.oschina.net
//Xcode连接git@osc:
http://my.oschina.net/zxs/blog/142544

//===========第一步：成生SSH密钥===========

打开终端命令工具，输入命令：ssh-keygen -t rsa -C "longpc@77ircloud.com"

注意ssh-keygen没有空格。屏幕输出：

Generating public/private rsa key pair.

Enter file in which to save the key (/Users/diaosi/.ssh/id_rsa):longpc

在上方输入生成的密钥文件名，如diaosi，屏幕输出：

Enter passphrase (empty for no passphrase): 输入密码

Enter same passphrase again: 确认密码

Your identification has been saved in longpc.

Your public key has been saved in diaosi.pub.

The key fingerprint is:

25:fd:01:00:89:98:49:bf:2e:ac:32:2e:d2:5d:bf:98 longpc@gmail.com

The key's randomart image is:

+--[ RSA 2048]----+

| ..+ ..o...      |

|  +.. .  . .     |

|    .   . o .    |

|     .   o . .   |

|    .   S   .    |

| . .  .          |

| .o... .         |

|=....  o.        |

|*o    E ..       |

+-----------------+

屏幕提示生成密钥文件成功，保存在/Users/diaosi文件夹下。

//===========第二步：把diaosi.pub中的内容加入git@osc 的SSH密钥中===========




//===========第三步：添加SSH并连接===========

输入命令：ssh-add ~/longpc

~/diaosi 是刚刚生成的密钥文件路径，屏幕输出：

Enter passphrase for /Users/longpc/longpc:输入密码

Identity added: /Users/longpc /longpc (/Users/longpc /longpc)

输入命令ssh -T git@git.oschina.net，屏幕输出：

The authenticity of host 'git.oschina.net (58.215.179.44)' can't be established.

RSA key fingerprint is 14:b8:b8:0b:c2:b2:5e:ae:f2:21:f8:18:4d:3a:be:fc.

Are you sure you want to continue connecting (yes/no)? yes（输入yes），屏幕输出：

Warning: Permanently added 'git.oschina.net,58.215.179.44' (RSA) to the list of known hosts.

Welcome to Git@OSC , longpc!

//===========第四步：设置个人信息===========

输入命令：

git config --global user.name "longpc"

git config --global user.email longpc@77ircloud.com
//=======================================================================================================

//=======================================================================================================
//===========将工程同步到git@git.oschina.net===========http://my.oschina.net/yongbin45/blog/144250
在你的git.oschina.net下“创建项目”。

在你的电脑上，为了以后管理方便，应该为OSChina上的项目建立一个文件夹统一管理，例如gitOSChina。在次级目录下存放每一个项目。

打开命令行工具，执行命令：

1cd gitOSChina/JBCalendar/           进入项目的目录
2git init                            初始化本地库（仅第一次时需要）
3git remote add origin git@git.oschina.net:armchannel/ydh-agent-ios.git  添加远程版本库的别名

git remote add origin git@git.oschina.net:armchannel/ydh-agent-ios2.git

4git add .       添加所有文件到版本库
5git commit -a -m "输入备注信息"    添加所有修改该版本库
6git push origin master      将修改推送到远程库
至此，新建工程完成了。


//===========更新工程===========
类似于创建项目时的操作，打开命令行工具，执行命令

1cd gitOSChina/JBCalendar/           进入项目的目录
2git pull origin master      从远程库获取并合并到本地库
3git add .       添加所有文件到版本库
4git commit -a -m "输入备注信息"    添加所有修改该版本库
5git push origin master      将修改推送到远程库

至此，更新完毕。






错误小结

1.
错误：

1
git pull origin master
2

3
ssh: Could not resolve hostname git.oschina.net:JustBen: nodename nor servname provided, or not known
4
fatal: Could not read from remote repository.
5
Please make sure you have the correct access rights and the repository exists.
解决方法：

view sourceprint?
01
重新设置SSH
02

03
cd
04
cd ~/.ssh/
05
ssh-keygen
06

07
Generating public/private rsa key pair.
08
Enter file in which to save the key (/Users/yongbin/.ssh/id_rsa):
09
/Users/yongbin/.ssh/id_rsa already exists.
10
Overwrite (y/n)? y
11
Enter passphrase (empty for no passphrase):
12
Enter same passphrase again:
13
Your identification has been saved in /Users/yongbin/.ssh/id_rsa.
14
Your public key has been saved in /Users/yongbin/.ssh/id_rsa.pub.
15
The key fingerprint is:
16
f8:87:a4:25:37:7c:bf:64:b1:4f:d5:e1:27:74:18:9e yongbin@YongbinZhang.local
17
The key's randomart image is:
18

19
+--[ RSA 2048]----+
20
|              .  |
21
|             . + |
22
|              E..|
23
|       o     ...o|
24
|      o S . . ..+|
25
|       B + . o o.|
26
|      . o . = .  |
27
|         . o +   |
28
|            . .  |
29
+-----------------+
30

31

32
cat id_rsa.pub | pbcopy     在git.oschina.net中添加一个SSH，直接复制到里面即可
33

34

35
cd ~/OSChina/JBCalendar/    进入工程目录
36

37
git add .
38
git commit -a -m "xxxxxxxxxxxxxx"
39
git pull origin master
40
git push origin master





